import {
	API
} from '@/config/index'

exports.refreshToken = async () => {
	try {
		const response = await uni.request({
			url: API + 'api/refreshToken',
			data: {
				openid: uni.getStorageSync('openid')
			},
			method: 'POST'
		});
		let res = response.data
		if (res.status === 200) {
			const tokenObj = {
				token: res.token,
				expiresAt: res.expiresAt
			}
			return tokenObj;
		} else {
			throw new Error(`Failed to refresh token: ${res.status}`);
		}
	} catch (error) {
		console.error('Error refreshing token:', error);
		throw error;
	}
}